package fun.shuofeng.juc.deadlock;

import java.util.concurrent.TimeUnit;

public class LiveLock {
    private static volatile long count = 50;

    public static void main(String[] args) {
        new Thread(() -> {
            while (count > 0) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count--;
                System.out.println("t1: " + count);
            }
        }, "t1").start();
        new Thread(() -> {
            while (count < 100) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count++;
                System.out.println("t2: " + count);
            }
        }, "t2").start();
    }
}
